package com.ruoyi.station.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.station.domain.SCondition;
import com.ruoyi.station.service.SConditionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * 追加条件Controller
 *
 * @author ruoyi
 * @date 2021-09-15
 */
@RestController
@RequestMapping("/condition")
@Api(value="追加条件对象操作资源", tags = "追加条件对象操作资源")
public class SConditionController extends BaseController
{
    @Autowired
    private SConditionService sConditionService;

    /**
     * 根据模块查询追加条件
     * @param model
     * @return
     */
    @GetMapping("/list/{model}")
    @ApiOperation(value="查询追加条件列表", notes="查询追加条件列表")
    public AjaxResult listByModel(@ApiParam @PathVariable String model)
    {
        List<Map> list = sConditionService.getListByModel(model);
        return AjaxResult.success(list);
    }

    /**
     * 查询追加条件列表
     */
    @PreAuthorize("@ss.hasPermi('system:condition:list')")
    @GetMapping("/list")
    @ApiOperation(value="查询追加条件列表", notes="查询追加条件列表")
    public TableDataInfo list()
    {
        QueryWrapper<SCondition> wrapper = new QueryWrapper();
        startPage();
        List<SCondition> list = sConditionService.list(wrapper);
        return getDataTable(list);
    }

    /**
     * 导出追加条件列表
     */
    @PreAuthorize("@ss.hasPermi('system:condition:export')")
    @Log(title = "追加条件", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    @ApiOperation(value="导出追加条件列表", notes="导出追加条件列表")
    public AjaxResult export()
    {
        QueryWrapper<SCondition> wrapper = new QueryWrapper();
        List<SCondition> list = sConditionService.list(wrapper);
        ExcelUtil<SCondition> util = new ExcelUtil<SCondition>(SCondition.class);
        return util.exportExcel(list, "condition");
    }

    /**
     * 获取追加条件详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:condition:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation(value="获取追加条件详细信息", notes="获取追加条件详细信息")
    public AjaxResult getInfo(@ApiParam @PathVariable("id") String id)
    {
        return AjaxResult.success(sConditionService.getById(id));
    }

    /**
     * 新增追加条件
     */
    @PreAuthorize("@ss.hasPermi('system:condition:add')")
    @Log(title = "追加条件", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value="新增追加条件", notes="新增追加条件")
    public AjaxResult add(@ApiParam @RequestBody SCondition sCondition)
    {
        sCondition.setCreateBy(SecurityUtils.getUsername());
        int result = sConditionService.save(sCondition) == true ? 1 : 0;
        return toAjax(result);
    }

    /**
     * 修改追加条件
     */
    @PreAuthorize("@ss.hasPermi('system:condition:edit')")
    @Log(title = "追加条件", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value="修改追加条件", notes="修改追加条件")
    public AjaxResult edit(@ApiParam @RequestBody SCondition sCondition)
    {
        int result = sConditionService.updateById(sCondition) == true ? 1 : 0;
        return toAjax(result);
    }

    /**
     * 删除追加条件
     */
    @PreAuthorize("@ss.hasPermi('system:condition:remove')")
    @Log(title = "追加条件", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation(value="删除追加条件", notes="删除追加条件")
    public AjaxResult remove(@ApiParam @PathVariable Long[] ids)
    {
        List<Long> list = Arrays.asList(ids);
        int result = sConditionService.removeByIds(list) == true ? 1 : 0;
        return toAjax(result);
    }
}
